import 'package:dio/dio.dart';

// dio接口封装
initDio() {
  BaseOptions _baseOptions = BaseOptions(
    baseUrl: 'http://eduboss.lagou.com',
    connectTimeout: 5000, // 请求超时
  );

  Dio dio = Dio(_baseOptions);

  // 拦截器
  dio.interceptors.add(
    InterceptorsWrapper(
      onRequest: (RequestOptions options){
        print('请求拦截');
      },
      onResponse: (Response response) {
        if (response.data == null || response.data['state'] != 1) {
          print('响应失败${response.data['message']}');
          response.data = null; 
        }
        return response;
      },
      onError: (DioError e) {
        return e;
      }
    ),
    
  );

  // 是否开启请求日志
  // dio.interceptors.add(LogInterceptor(responseBody: false)); //开启请求日志

  return dio;
}